<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #app{
            text-align: center;
        }
        .box{
            width: 500px;
            margin: 0 auto;
            display: flex;
            flex-flow: row wrap;
            animation: move ;
        }
        .box .item{
            overflow: hidden;
            border: 1px solid black;
            border-radius: 8px;
            width: 20%;
            font-size: 30px;
            line-height: 60px;
            text-align: center;
            flex-shrink: 0;
            margin: 10px;
            transition: all 500ms ease-in-out;
        }
        .box .item.active{
            background-color: orangered;
            color: white;
        }
        .btn{
            margin-top: 10px;
        }
    </style>
</head>
<body>
    <div id="app" >
        <div class="box">
            <div class="item" :class="{ active:activeIndex==i }" v-for="(stu,i) in students">{{ stu }}</div>
        </div>
        <input class="btn" type="button" value="点名" @click="randomStu()">
    </div>
    <script type="module">
        import { createApp } from "./assets/vue.esm-browser.js"
        createApp({
            data(){
                return {
                    activeIndex:null,
                    students:[
                        "杨颖",
                        "厉元海",
                        "居天奕",
                        "叶逸尘",
                        "崔林",
                        "张宇",
                        "许亚",
                        "陈俊宇",
                        "张睿",
                        "高振远",
                        "王煜",
                        "李欣",
                        "杨华国",
                        "王鑫宇",
                        "候新澳"
                    ]
                }
            },
            methods:{
                randomStu(){
                    let num = 10;
                    let timer = setInterval(()=>{
                        if(num==0){
                            clearInterval(timer)
                        }else{
                            let i = Math.floor(Math.random()*this.students.length)
                            this.activeIndex = i;
                            num--;
                        }
                    },200)
                }
            }
        }).mount("#app")
    </script>
</body>
</html>